package interfaces.spawnMenu.costumize.items;

import fileHandling.language.interfaces.SpawnMenuText;

import interfaces.GUISource;
import interfaces.language.LanguageLabel;
import interfaces.spawnMenu.AbsSpawnMenu;
import interfaces.spawnMenu.costumize.CustomizeContainer;
import logic.common.team.Team;
import logic.items.ItemProperties;
import logic.ships.hunter.Hunter;
import logic.weapons.WeaponType;

public class ItemSelectContent extends CustomizeContainer<ItemProperties> {
	
	private ItemBuyContent itemBuyContent;
	
	private int border, contentWidth, contentX, projectilesHeight;
	
	private LanguageLabel noHunterLabel;
	private ProjectilesContent heatSeekerContent, missileContent;
	private AbsSpawnMenu spawnMenu;
	
	public ItemSelectContent(Team team, int width, int height, AbsSpawnMenu spawnMenu) {
		super(team, width, height);
		this.spawnMenu = spawnMenu;
		
		border = height / 34;
		contentWidth = width - (2 * border);
		contentX = border;
		
		initNoHunterLabel();
		initProjectileContents();
		
		layout();
	}
	
	private void initNoHunterLabel() {
		noHunterLabel = new LanguageLabel(SpawnMenuText.Select_Hunter_first, GUISource.bigFont);
		noHunterLabel.setSize(height / 2, height / 10);
		noHunterLabel.setXY(height / 3, height / 2);
		addWidget(noHunterLabel);
	}
	
	private void initProjectileContents() {
		int contentHeight = GUISource.middleFont.getHeight();
		projectilesHeight = contentHeight * 2;
		int x = contentX;
		int y = border + contentHeight;
		
		heatSeekerContent = new ProjectilesContent(contentWidth, contentHeight, x, y, WeaponType.HeatSeeker, spawnMenu);
		y -= contentHeight;
		missileContent = new ProjectilesContent(contentWidth, contentHeight, x, y, WeaponType.Missile, spawnMenu);
	}
	
	private void initItemBuyContent() {
		int itemHeight = height - projectilesHeight - (3 * border);
		
		itemBuyContent = new ItemBuyContent(contentWidth, itemHeight, hunter, spawnMenu);
		itemBuyContent.setXY(contentX, height - itemHeight - border);
		addWidget(itemBuyContent);
	}
	
	@Override
	public void changeHunter(Hunter h) {
		super.changeHunter(h);
		
		if(hunter == null) initNoHunterLabel();
		else {
			initItemBuyContent();
			
			heatSeekerContent.changeHunter(hunter);
			addWidget(heatSeekerContent);
			
			missileContent.changeHunter(hunter);
			addWidget(missileContent);
		}
		
		layout();
	}
	
	@Override
	public void updateMoney(int newMoney) {
		if(itemBuyContent != null) itemBuyContent.updateMoney(newMoney);
	}
	
	@Override
	public void restore() {
		
	}
}